<!DOCTYPE html>
<html>
	<head>
		<title>陕西省核工业二一五医院救护车平台</title>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
		<script type="text/javascript" src="https://api.map.baidu.com/api?v=3.0&ak=BNifMUiEScwDWA8B6YhxEv9qdKT7nNOF"></script>
		<style type="text/css">
			body, html,
			#allmap {width: 100%;height: 100%;overflow: hidden;margin:0;font-family:"微软雅黑";}
			#l-map{height:100%;width:78%;float:left;border-right:2px solid #bcbcbc;}
			#r-result{height:100%;width:20%;float:left;}
			.BMap_cpyCtrl {
				display: none;
			}
			.anchorBL {
				display: none;
			}
		</style>
	</head>
	<body>
		<div id="allmap"></div>
	</body>
	<script type='text/javascript' src='./js/jquery-1.7.2.min.js' charset='utf-8'></script>
	<script type="text/javascript">
		var hosPoint={
			hospitalLongitude:108.703123,
			hospitalLatitude:34.334944
		};
		map = new BMap.Map("allmap");
		map.centerAndZoom(new BMap.Point(hosPoint.hospitalLongitude, hosPoint.hospitalLatitude), 12);
		var navigationControl = new BMap.NavigationControl({
		    anchor: BMAP_ANCHOR_TOP_LEFT,
		    type: BMAP_NAVIGATION_CONTROL_LARGE,
		    enableGeolocation: true
		});
		map.addControl(navigationControl);
		/* map.setMapStyleV2({
		  styleId: 'e280a32365003108dccdc8ad963a3d80'
		}); */
		map.setDefaultCursor("url('bird.cur')");
		map.enableScrollWheelZoom();
		map.enableContinuousZoom();
		function createCluster(dataList) {
			map.clearOverlays();
			var latlngs = [];
			var hospitalList = [];
			for (var i = 0; i < dataList.length; i++) {
				if (hospitalList.indexOf(dataList[i].hospitalId) == -1) {
					hosPoint = dataList[i];
					hospitalList.push(dataList[i].hospitalId);
					var hospitalPoint = new BMap.Point(dataList[i].hospitalLongitude,dataList[i].hospitalLatitude);
					var myIcon = new BMap.Icon("./js/yiyuan3.png", new BMap.Size(52,50));
					var marker = new BMap.Marker(hospitalPoint,{icon:myIcon});
					map.addOverlay(marker);      
					var opts = {
					  position : hospitalPoint,
					  offset   : new BMap.Size(0, -43)
					}
					var label = new BMap.Label("<div>【"+ dataList[i].hospitalName + "】</div>", opts);
					label.setStyle({
						 color : "red",
						 fontSize : "12px",
						 height : "20px",
						 lineHeight : "20px",
						 fontFamily:"微软雅黑"
					});
					map.addOverlay(label);
				}
				
				if(dataList[i].visitUserId != null && dataList[i].visitUserId > 0){
					var visitPosition = new BMap.Point(dataList[i].visitLongitude,dataList[i].visitLatitude);
					var cheIcon = new BMap.Icon("./js/che.png", new BMap.Size(52,50));
					var cheMarker = new BMap.Marker(visitPosition,{icon:cheIcon});
					map.addOverlay(cheMarker);
					
					var opts = {
					  position : visitPosition,
					  offset   : new BMap.Size(0, -70)
					}
					
					var info = "";
					if (dataList[i].visitTaskId != null && dataList[i].visitTaskId > 0) {
						info = "<div>【"+ dataList[i].hospitalName + "】</div><div>司机："+ dataList[i].visitName + "【<span style='color:red'>出诊</span>】</div>";
					} else {
						info = "<div>【"+ dataList[i].hospitalName + "】</div><div>司机："+ dataList[i].visitName + "【空闲】</div>";
					}
					var cheLabel = new BMap.Label(info, opts);
					cheLabel.setStyle({
						 color : "",
						 fontSize : "12px",
						 height : "40px",
						 lineHeight : "20px",
						 fontFamily:"微软雅黑",
					});
					map.addOverlay(cheLabel);
				}
				
				//患者
				if (dataList[i].visitTaskId != null && dataList[i].visitTaskId > 0) {
					var patientPosition = new BMap.Point(dataList[i].patientLongitude,dataList[i].patientLatitude);
					var patientIcon = new BMap.Icon("./js/people2.png", new BMap.Size(43,44));
					var patientMarker = new BMap.Marker(patientPosition,{icon:patientIcon});
					map.addOverlay(patientMarker);
					
					var opts = {
					  position : patientPosition,
					  offset   : new BMap.Size(0, -70)
					}
					
					var info = "<div>【"+ dataList[i].hospitalName + "】</div><div>患者姓名："+ dataList[i].patientName + "</div>";
					var patientLabel = new BMap.Label(info, opts);
					patientLabel.setStyle({
						 color : "",
						 fontSize : "12px",
						 height : "40px",
						 lineHeight : "20px",
						 fontFamily:"微软雅黑",
					});
					map.addOverlay(patientLabel);
				}
			}
		};
		
		function addItems() {
			jQuery.ajax({
				url: "https://www.smtaiot.com:9000/consumer/tasks/sosAmbulanceLocation",
				type: "GET",
				data: {
					'hospitalId': 21,
				},
				error: function() {
					console.log(d);
				},
				success: function(data) {
					var datas = [];
					if (data.success == true) {
						const list = data.data;
						createCluster(list);
					} else {
						console.log("获取信息失败!");
					}
				}
			});
		}
		setInterval(function() {
			addItems();
		}, 2000);
	</script>
</html>
